﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class MotionSystem : IGameSystem {
    private Mediator m_mediator;
    private Transform floorTransform;
    private float speed = 2;
    public MotionSystem (Mediator mediator){
        this.m_mediator = mediator;
        floorTransform = GameObject.Find ("Floor").transform;
    }

    
    public  void OnEnd () {

        floorTransform.GetComponent<Rigidbody> ().velocity = Vector2.zero;
    }
    public  void OnStart () {
        floorTransform.GetComponent<Rigidbody> ().velocity = new Vector3 (speed * 1, 0, 0);
    }
    public  void OnUpdate () {
        if (floorTransform != null) {

            if (Camera.main.WorldToViewportPoint (floorTransform.transform.position).x >= 1) {
                floorTransform.GetComponent<Rigidbody> ().velocity = new Vector3 (speed * -1, 0, 0);
            }
            if (Camera.main.WorldToViewportPoint (floorTransform.transform.position).x <= 0) {
                floorTransform.GetComponent<Rigidbody> ().velocity = new Vector3 (speed * 1, 0, 0);
            }
            
        }
    }
}